/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainLayout.java
 *
 * Created on 06/10/2011, 11:51:56
 */
package wf.ui.layouts;

import bc.dsl.PageDSL;
import bc.swing.pfrm.Page;
import bc.swing.pfrm.PageLayout;
import java.awt.Color;
import javax.swing.JComponent;

/**
 *
 * @author bennyl
 */
public class MainLayout extends javax.swing.JPanel implements PageLayout {

    public static final String USER_NAME_ROLE = "USER NAME ROLE";
    public static final String VIEWS_ROLE = "VIEWS ROLE";
    Page page;

    /** Creates new form MainLayout */
    public MainLayout() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        apaintar = new org.jdesktop.swingx.painter.AlphaPainter();
        gpainter = new org.jdesktop.swingx.painter.GlossPainter();
        bground = new javax.swing.JPanel();
        headerPanel = new org.jdesktop.swingx.JXPanel();
        icon = new javax.swing.JLabel();
        caption = new javax.swing.JLabel();
        centerPanel = new javax.swing.JPanel();
        viewsPan = new javax.swing.JPanel();
        footerPanel = new javax.swing.JPanel();
        unameString = new javax.swing.JLabel();
        unamePan = new javax.swing.JPanel();
        placeHolder = new javax.swing.JLabel();
        actionsPan = new javax.swing.JPanel();

        setLayout(new java.awt.BorderLayout());

        bground.setBackground(new java.awt.Color(255, 255, 255));
        bground.setLayout(new java.awt.GridBagLayout());

        headerPanel.setBackground(new java.awt.Color(186, 221, 255));
        headerPanel.setBackgroundPainter(gpainter);
        headerPanel.setPreferredSize(new java.awt.Dimension(100, 60));
        headerPanel.setLayout(new java.awt.GridBagLayout());

        icon.setFont(new java.awt.Font("Showcard Gothic", 0, 18));
        icon.setForeground(new java.awt.Color(102, 102, 102));
        icon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/img/logo128.png"))); // NOI18N
        icon.setText("Waterfall");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        headerPanel.add(icon, gridBagConstraints);

        caption.setForeground(new java.awt.Color(153, 153, 153));
        caption.setText("Watering System Managment");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(38, 140, 0, 0);
        headerPanel.add(caption, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        bground.add(headerPanel, gridBagConstraints);

        centerPanel.setBackground(new java.awt.Color(186, 221, 255));
        centerPanel.setLayout(new java.awt.BorderLayout());

        viewsPan.setBackground(new java.awt.Color(186, 221, 255));
        viewsPan.setBorder(javax.swing.BorderFactory.createMatteBorder(3, 3, 0, 3, new java.awt.Color(186, 221, 255)));

        javax.swing.GroupLayout viewsPanLayout = new javax.swing.GroupLayout(viewsPan);
        viewsPan.setLayout(viewsPanLayout);
        viewsPanLayout.setHorizontalGroup(
            viewsPanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 632, Short.MAX_VALUE)
        );
        viewsPanLayout.setVerticalGroup(
            viewsPanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 305, Short.MAX_VALUE)
        );

        centerPanel.add(viewsPan, java.awt.BorderLayout.CENTER);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 1.0;
        bground.add(centerPanel, gridBagConstraints);

        footerPanel.setBackground(new java.awt.Color(102, 102, 102));
        footerPanel.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createMatteBorder(3, 0, 3, 0, new java.awt.Color(186, 221, 255)), javax.swing.BorderFactory.createMatteBorder(1, 0, 1, 0, new java.awt.Color(255, 255, 255))));
        footerPanel.setMinimumSize(new java.awt.Dimension(0, 35));
        footerPanel.setPreferredSize(new java.awt.Dimension(0, 35));
        footerPanel.setLayout(new java.awt.GridBagLayout());

        unameString.setForeground(new java.awt.Color(255, 255, 255));
        unameString.setText("Connected As:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        footerPanel.add(unameString, gridBagConstraints);

        unamePan.setOpaque(false);

        javax.swing.GroupLayout unamePanLayout = new javax.swing.GroupLayout(unamePan);
        unamePan.setLayout(unamePanLayout);
        unamePanLayout.setHorizontalGroup(
            unamePanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        unamePanLayout.setVerticalGroup(
            unamePanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        footerPanel.add(unamePan, gridBagConstraints);

        placeHolder.setForeground(new java.awt.Color(255, 255, 255));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        footerPanel.add(placeHolder, gridBagConstraints);

        actionsPan.setOpaque(false);
        footerPanel.add(actionsPan, new java.awt.GridBagConstraints());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        bground.add(footerPanel, gridBagConstraints);

        add(bground, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel actionsPan;
    private org.jdesktop.swingx.painter.AlphaPainter apaintar;
    private javax.swing.JPanel bground;
    private javax.swing.JLabel caption;
    private javax.swing.JPanel centerPanel;
    private javax.swing.JPanel footerPanel;
    private org.jdesktop.swingx.painter.GlossPainter gpainter;
    private org.jdesktop.swingx.JXPanel headerPanel;
    private javax.swing.JLabel icon;
    private javax.swing.JLabel placeHolder;
    private javax.swing.JPanel unamePan;
    private javax.swing.JLabel unameString;
    private javax.swing.JPanel viewsPan;
    // End of variables declaration//GEN-END:variables

    @Override
    public void setPage(Page page) {
        this.page = page;
        PageDSL.fillByRole(page, viewsPan, VIEWS_ROLE);

        final JComponent unameView = PageDSL.viewByRole(page, USER_NAME_ROLE);
        if (unameView != null) {
            unameView.setForeground(Color.WHITE);
        }
        
        PageDSL.fillByRole(page, unamePan, USER_NAME_ROLE);
        PageDSL.appendActions(page.getActions(), actionsPan);

        caption.setText(page.getName());
        icon.setIcon(page.getIcon());
        validate();
        repaint();
    }

    @Override
    public void onDispose() {
    }
}
